package td.projectiles
{
	import flash.display.Graphics;
	import flash.events.Event;
	import td.Creep;

	/**
	 * IceBullet class.
	 * 
	 * @author Garth Henson - Guahan Web (garth@guahanweb.com)
	 */
	public class PoisonBullet extends Bullet
	{
		/**
		 * Constructor method
		 * 
		 * @constructor
		 * @access public
		 * @param {Object} t the target object
		 * @return IceBullet
		 */
		public function PoisonBullet(t:Creep)
		{
			super(t);
		}
		
		/**
		 * override  trackTarget
		 * 跟踪目标后攻击加上中毒效果
		 * @param	e
		 */
		protected override function trackTarget(e:Event) :void
		{
			var diffX :Number = this.target.x - this.x;
			var diffY :Number = this.target.y - this.y;
			var dist :Number  = Math.abs(Math.sqrt((diffX * diffX) + (diffY * diffY)));
			var ratio :Number = speed / dist;
			
			if (dist <= speed)
			{
				// We hit them!
				this.target.hit(this);
				this.target.bleed(200);//中毒测试
				
				this.alpha = 0;
				this.is_destroyed = true;
				removeEventListener(Event.ENTER_FRAME, trackTarget);
			}
			else
			{
				x += Math.round(diffX * ratio);
				y += Math.round(diffY * ratio);
			}
		}
		
		
		/**
		 * Draws the visuals for our bullet
		 * 
		 * @return void
		 */
		protected override function draw() :void
		{
			var g :Graphics = this.graphics;
			g.lineStyle(1, 0x000077);
			g.beginFill(0xaaaaff);
			g.drawCircle(0, 0, 4);
			g.endFill();
		}
	}
}